package com.cupk.mapper;

import com.cupk.pojo.Match;
import com.cupk.pojo.Result;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface MatchMapper {
    @Select("select `match`.*, user.name AS username from `match`, user where `match`.user = user.id and `match`.id = #{userId} and `match`.name like concat('%',#{name},'%')")
    List<Match> getMyList(Integer userId, String name);

    @Select("select `match`.*, user.name AS username from `match`,user"
            + " where `match`.user = user.id and `match`.name like concat('%',#{name},'%')")
    List<Match> getAllList(String name);

    @Select("select * from `match` where name = #{name} and session = #{session}")
    List<Match> getMatchListByNameAndSession(String name, Integer session);

    @Insert("insert into `match`(name,session,user,start_time,end_time,description,status) values (#{name},#{session},#{user},#{startTime},#{endTime},#{description},#{status})")
    void addMatch(Match match);

    @Select("select `match`.*, user.name AS username from `match`,user where `match`.user = user.id and `match`.id = #{id}")
    Match getMatchById(Integer id);

    @Update("update `match` set name = #{name}, session = #{session} , `user` = #{user} , start_time = #{startTime} , end_time = #{endTime} , description = #{description} , status = #{status} where id =#{id}")
    void updateMatch(Match match);

    @Select("select * from `match` where start_time <= #{nowTime} and end_time >= #{nowTime}")
    List<Match> getAvailableListByTime(LocalDateTime nowTime);

    @Delete("delete from `match` where id = #{matchId}")
    void deleteMatch(Integer matchId);
}
